package org.kabeja.parser.entities;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.DXFDocument;
import org.kabeja.dxf.entity.DXFEntity;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 11:16
 */
public abstract class AbstractEntityHandler implements DXFEntityHandler {
    public static final int ELEMENT_REFERENCE = 5;
    public static final int GROUPCODE_START_X = 10;
    public static final int GROUPCODE_START_Y = 20;
    public static final int GROUPCODE_START_Z = 30;
    public static final int END_X = 11;
    public static final int END_Y = 21;
    public static final int END_Z = 31;
    public static final int LAYER_NAME = 8;
    public static final int TRANSPARENCY = 440;
    public static final int COLOR_CODE = 62;
    public static final int COLORNAME = 430;
    public static final int COLOR_24BIT = 420;
    public static final int COLOR_TRANSPARENCY = 440;
    public static final int FLAGS = 70;
    public static final int EXTRUSION_X = 210;
    public static final int EXTRUSION_Y = 220;
    public static final int EXTRUSION_Z = 230;
    public static final int VISIBILITY = 60;
    public static final int LINE_TYPE = 6;
    public static final int LINE_TYPE_SCALE = 48;
    public static final int LINE_WEIGHT = 370;
    public static final int GROUPCODE_THICKNESS = 39;
    public static final int GROUPCODE_STYLENAME = 3;
    public static final int GROUPCODE_TEXT = 1;
    public static final int GROUPCODE_ROTATION_ANGLE = 50;
    public static final int GROUPCODE_MODELSPACE = 67;
    protected DXFDocument doc;

    public AbstractEntityHandler() {
    }

    @Override
    public void setDXFDocument(DXFDocument var1) {
        this.doc = var1;
    }

    protected void parseObjectProperty(int var1, DXFValue var2, int type, DXFEntity var3) {
        if (var3 == null) {
            return;
        }
        switch (type) {
            case DXFConstants.ACAD_XDICTIONARY_CODE:
                switch (var1) {
                    case 360:
                        var3.setDictionaryId(var2.getValue());
                        break;
                    default:
                        System.out.println("{ACAD_XDICTIONARY未知对象扩展类型：" + var2.getValue());
                }
                break;
            case DXFConstants.ACAD_REACTORS_CODE:
                switch (var1) {
                    case 330:
                        var3.setReactorsId(var2.getValue());
                        break;
                    default:
                        System.out.println("{ACAD_REACTORS未知对象扩展类型：" + var2.getValue());
                }
                break;
            default:
                // 其它扩展对象信息
                break;
        }
    }

    protected void parseCommonProperty(int var1, DXFValue var2, DXFEntity var3) {
        switch(var1) {
            case 5:
                var3.setID(var2.getValue());
                break;
            case 6:
                var3.setLineType(var2.getValue());
                break;
            case 8:
                var3.setLayerName(var2.getValue());
                break;
            case 39:
                var3.setThickness(var2.getDoubleValue());
                break;
            case 48:
                var3.setLinetypeScaleFactor(var2.getDoubleValue());
                break;
            case 60:
                var3.setVisibile(!var2.getBooleanValue());
                break;
            case 62:
                var3.setColor(var2.getIntegerValue());
                break;
            case 67:
                var3.setModelSpace(var2.getBooleanValue());
                break;
            case 70:
                var3.setFlags(var2.getIntegerValue());
                break;
            case 210:
                var3.setExtrusionX(var2.getDoubleValue());
                break;
            case 220:
                var3.setExtrusionY(var2.getDoubleValue());
                break;
            case 230:
                var3.setExtrusionZ(var2.getDoubleValue());
                break;
            case 370:
                var3.setLineWeight(var2.getIntegerValue());
            case 420:
                break;
            case 440:
                break;
            default:
                break;
        }

    }

    @Override
    public abstract String getDXFEntityName();

    @Override
    public void releaseDXFDocument() {
        this.doc = null;
    }
}
